import request from '@/utils/request'
import $util from '@/utils/util'

// 查询系统参数
export function getSetting(module, name) {
  return new Promise((resolve, reject) => {
    request({
      url: '/sys/setting/get',
      method: 'get',
      params: { module: module, name: name }
    }).then((result) => {
      const val = result.data
      const v = $util.decrypt(val)
      resolve(v)
    }).catch((e) => {
      reject(e)
    })
  })
}
export function getSettingMap(module) {
  return new Promise((resolve, reject) => {
    request({
      url: '/sys/setting/map',
      method: 'get',
      params: { module: module }
    }).then(result => {
      const r = {}
      const m = result.data
      if (m) {
        for (const k in m) {
          r[k] = $util.decrypt(m[k])
        }
      }
      resolve(r)
    }).catch((e) => {
      reject(e)
    })
  })
}
export function getPubKey() {
  return getSetting('system', 'pub_key')
}
export function getVersion() {
  return getSetting('system', 'version')
}
// 保存密码安全策略
export function savePasswordPolicy(data) {
  return request({
    url: '/sys/setting/savePasswordPolicy',
    method: 'post',
    data: data
  })
}
// 保存系统安全策略
export function saveSystemPolicy(data) {
  return request({
    url: '/sys/setting/saveSystemPolicy',
    method: 'post',
    data: data
  })
}
// 获取服务信息
export function getServerInfo() {
  return request({
    url: '/sys/server/info',
    method: 'get'
  })
}
// 保存黑名单
export function saveBlackList(data) {
  return request({
    url: '/sys/blackList/save',
    method: 'post',
    data: data
  })
}
